<template>
	<div class="view">
		<Table highlight-row border stripe :loading="data.loading" :columns="columns" :data="data.data">
		</Table>
	</div>
</template>

<script>
	export default {
		props: ['data'],
		data() {
			return {
				columns: [{
						type: 'index',
						width: 60,
						fixed: 'left',
						align: 'center'
					},
					{
						title: '名称',
						key: 'name',
						width: 275,
						fixed: 'left',
						align: 'center'
					},
					{
						title: '是否全部',
						key: 'isAll',
						align: 'center',
						render: (h, params) => {
							if(params.row.isAll == 1) {
								return '有';
							} else {
								return '无';
							}
						}
					},
					{
						title: '是否可设置',
						key: 'isSet',
						align: 'center',
						render: (h, params) => {
							if(params.row.isSet == 1) {
								return '是';
							} else {
								return '否';
							}
						}
					},
					{
						title: '状态',
						key: 'state',
						width: 100,
						fixed: 'right',
						align: 'center',
						render: (h, params) => {
							return params.row.state == 1 ? "正常" : "禁用";
						}
					},
					{
						title: '操作',
						key: 'state',
						width: 180,
						fixed: 'right',
						align: 'center',
						render: (h, params) => {
							return h('div', [
								h('Button', {
									props: {
										type: 'primary',
										size: 'small'
									},
									style: {
										marginRight: '5px'
									},
									on: {
										click: () => {
											this.editItem(params)
										}
									}
								}, '编辑'),
								h('Button', {
									props: {
										type: (params.row.state == 0 ? 'primary' : 'error'),
										size: 'small'
									},
									style: {
										marginRight: '5px'
									},
									on: {
										click: () => {
											this.editItem2State(params)
										}
									}
								}, (params.row.state == 1 ? '禁用' : '启用')),
								h('Button', {
									props: {
										type: 'error',
										size: 'small'
									},
									on: {
										click: () => {
											this.deleteItem(params)
										}
									}
								}, '删除')
							]);
						}
					}
				]
			}
		},
		methods: {
			editItem(data) {
				this.$emit('on-action', 'editItem', data);
			},
			editItem2State(data) {
				this.$emit('on-action', 'editItem2State', data);
			},
			deleteItem(data) {
				this.$emit('on-action', 'deleteItem', data);
			}
		}
	}
</script>

<style scoped="scoped">

</style>